var failureAreaChar;

var cellTable;
var terminalTable;
var userTable;
var apnTable;

$(function() {
	// 图表
	failureAreaChar = echarts.init(document.getElementById('failureAreaChar'));
//	failureAreaChar.on('click', function(param) {
//		failLinkTo(param.seriesName,param.name)
//	})
	
	var beginDate=$("#beginDate").val();
	var endDate=$("#endDate").val();
	var signal_process=$("#signal_process").val();
	var failureType=$("#failureType").val();
	
	initAreaFailureCountChar();
	initCellTable();
	initUserTable();
	initTerminalTable();
	initAPNTable();
	
	failureAreaChar.on('click', function(param) {
		failureAreaLinkTo(param.name);
	});
})

function failureAreaLinkTo(city_code) {
	var jspType = "interfaceFailStatisticsForArea";
	var signal_process = $("#signal_process").val();
	var failureType = $("#failureType").val();
	var interfaceType= $("#interfaceType").val();
	var beginDate = $("#beginDate").val();
	var endDate = $("#endDate").val();
	var dateType = $("#dateType").val();
	
	var url="/kpi/userFailureLink/index?beginDate="+beginDate+"&endDate="+endDate+"&city_code="+city_code+"&dateType="+dateType
	+"&jspType="+jspType+"&procedureType="+signal_process+"&failureType="+failureType+"&interfaceType="+interfaceType;
	linkTab("失败用户",url);
}
//function failLinkTo(name,eCharsTime) {
//	var p ="flag=1&timeSize=" + param.timeSize + "&sgw=" + param.netYuan + "&tac="
//			+ param.tai + "&cityCode=" + param.city_code + "&areaHouse="
//			+ param.cell_id + "&eNodeBID=" + param.enodeb_id + "&groupId="
//			+ param.usergroup + "&userId=" + param.msisdn + "&terminalBrandId="
//			+ param.terminal_brand + "&terminalModelId=" + param.terminal_model
//			+ "&apn=" + param.apn  + "&tac_check=" + param.tai_check +"&enodebid_check=" +  param.enodebid_check + "&cell_id_check=" + param.cell_id_check
//	switch (this.dimension) {
//	case "area":
//		p += "&selectRadio=4"
//		break;
//	case "user":
//		p += "&selectRadio=1"
//		break;
//	// case "apn":
//	// param="&selectRadio="
//	// break;
//	case "usergroup":
//		p += "&selectRadio=0"
//		break;
//	case "terminal_type":
//		p += "&selectRadio=2"
//		break;
//	}
//	if (name == '查询时间') {
//		p += "&queryDate=" + param.queryDate
//	}
//	if (name == '对比时间') {
//		p += "&queryDate=" + param.compareDate
//	}
//	p += "&eCharsTime="+eCharsTime
//	url = "/businessAnalysis/attachment/index?" + p;
//	title = "接口故障"
//	linkTab(title, url)
//}




//function getList(){
//	
//	initAreaFailureCountChar();
//	initCellTable();
//	initTerminalTable();
//	initUserTable();
//	initAPNTable();
//	
//}





function initAreaFailureCountChar(){
	
	var beginDate=$("#beginDate").val();
	var endDate=$("#endDate").val();
	var signal_process=$("#signal_process").val();
	var failureType=$("#failureType").val();
	var interfaceType = $("#interfaceType").val();
	//查询  
	failureAreaChar.clear();
	failureAreaChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../kpi/failurecount/getCityFailureCountChar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"beginDate" : beginDate,
			"endDate" : endDate,
			"signal_process" : signal_process,
			"failureType" : failureType,
			"interfaceType" : interfaceType
			
		},
		success : function(data) {
			failureAreaChar.setOption(data, true);
			failureAreaChar.hideLoading();
		}
	});
}
 
function initCellTable(){
	
	var beginDate=$("#beginDate").val();
	var endDate=$("#endDate").val();
	var signal_process=$("#signal_process").val();
	var failureType=$("#failureType").val();
	var interfaceType = $("#interfaceType").val();
	
	var timeSize=$('input:radio[name="timeSize"]:checked').val();
	$("#userTable tbody tr").remove();
	if (cellTable == undefined || cellTable == "undefined" || cellTable == null) {
	} else {
		cellTable.destroy();
	}
	cellTable = $('#cellTable')
				.DataTable(
				{
					"aoColumnDefs" : [ {
						sDefaultContent : '',
						aTargets : [ '_all' ]
					} ],
					"bPaginate" : false, // 翻页功能
					"bLengthChange" : false, // 改变每页显示数据数量
					"bFilter" : false, // 过滤功能
					"bSort" : false, // 排序功能
					"bInfo" : false,// 页脚信息
					"bAutoWidth" : true,// 自动宽度
					// "sPaginationType": "full_numbers",//显示分页的样式
					// 还有simple_numbers等
	//				"sScrollX" : "100%",
					"sScrollXInner" : "110%",
					"bScrollCollapse" : true,
					"oLanguage" : {
						"sLengthMenu" : "每页显示 _MENU_条",
						"sZeroRecords" : "没有找到符合条件的数据",
						"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
						"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
						"sInfoEmpty" : "没有记录",
						"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
						"sSearch" : "搜索：",
						"oPaginate" : {
							"sFirst" : "首页",
							"sPrevious" : "前一页",
							"sNext" : "后一页",
							"sLast" : "尾页"
						}
					},
					"bProcessing" : true,
					"bServerSide" : true,
						"sAjaxSource" : "../../kpi/failurecount/getCellTable",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"beginDate" : beginDate,
											"endDate" : endDate,
											"signal_process" : signal_process,
											"failureType" : failureType,
											"interfaceType" : interfaceType
										}, // 以json格式传递
										"success" : function(resp) {
											fnCallback(resp.allData);
										}
									});
						},
						columns : [
								{
									data : "report_date"
								},
								{
									data : "city_code"
								},
								{
									data : "enodeb_id"
								},
								{
									data : "cell_name"
								},
								{
									data : "failurecount",
									render : function(value,type,row){
										
										return "<a href='#' onclick=\"failureCountCellDetail('"
											+ row.report_date + "','"
											+ row.city_code + "','"
											+ row.enodeb_id + "','"
											+ row.cell_name
											+ "')\"  >"+ value + "</a>";
									}
								}]
		});
}

function failureCountCellDetail(report_date,city_code,enodeb_id,cell_name){
	var jspType = "interfaceFailStatisticsForCell";
	var signal_process = $("#signal_process").val();
	var failureType = $("#failureType").val();
	var interfaceType= $("#interfaceType").val();
	var dateType = $("#dateType").val();
	
	var url="/kpi/userFailureLink/index?beginDate="+report_date+"&endDate="+report_date
	+"&city_code="+city_code+"&enodeb_id="+enodeb_id+"&cell_name="+cell_name.trim()+"&jspType="+jspType
	+"&procedureType="+signal_process+"&failureType="+failureType+"&interfaceType="+interfaceType+"&dateType="+dateType;
	linkTab("失败用户",url);
}

function initTerminalTable(){
	var beginDate=$("#beginDate").val();
	var endDate=$("#endDate").val();
	var signal_process=$("#signal_process").val();
	var failureType=$("#failureType").val();
	$("#spTable tbody tr").remove();
	if (terminalTable == undefined || terminalTable == "undefined" || terminalTable == null) {
	} else {
		terminalTable.destroy();
	}
	terminalTable = $('#terminalTable')
			.DataTable(
					{
						"aoColumnDefs" : [ {
							sDefaultContent : '',
							aTargets : [ '_all' ]
						} ],
						"bPaginate" : false, // 翻页功能
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"bSort" : false, // 排序功能
						"bInfo" : false,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
						"sScrollX" : "100%",
						"sScrollXInner" : "110%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../../kpi/failurecount/getTerminalTable",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$
									.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"beginDate" : beginDate,
											"endDate" : endDate,
											"signal_process" : signal_process,
											"failureType" : failureType,
											"interfaceType" : $("#interfaceType").val()
										}, // 以json格式传递
										"success" : function(resp) {
											fnCallback(resp.allData);
										}
									});
						},
						columns : [
								{
									data : "report_date"
								},
								{
									data : "terminal_model"
								},
								{
									data : "terminal_brand"
								},
								{
									data : "failurecount",
									render : function(value,type,row){
										
										return "<a href='#' onclick=\"failureCountTerminalDetail('"
											+ row.report_date + "','"
											+ row.terminal_model + "','"
											+ row.terminal_brand 
											+ "')\"  >"+ value + "</a>";
									}
								}]
		});
}

function failureCountTerminalDetail(report_date,terminal_model,terminal_brand){
	var jspType = "interfaceFailStatisticsForTerminal";
	var signal_process = $("#signal_process").val();
	var failureType = $("#failureType").val();
	var interfaceType= $("#interfaceType").val();
	var dateType = $("#dateType").val();
	
	var url="/kpi/userFailureLink/index?beginDate="+report_date+"&endDate="+report_date
	+"&terminal_model="+terminal_model+"&terminal_brand="+terminal_brand+"&jspType="+jspType
	+"&procedureType="+signal_process+"&failureType="+failureType+"&interfaceType="+interfaceType+"&dateType="+dateType;
	linkTab("失败用户",url);
}

function initUserTable(){
	var beginDate=$("#beginDate").val();
	var endDate=$("#endDate").val();
	var signal_process=$("#signal_process").val();
	var failureType=$("#failureType").val();
	$("#userTable tbody tr").remove();
	if (userTable == undefined || userTable == "undefined" || userTable == null) {
	} else {
		userTable.destroy();
	}
	userTable = $('#userTable')
			.DataTable(
					{
						"aoColumnDefs" : [ {
							sDefaultContent : '',
							aTargets : [ '_all' ]
						} ],
						"bPaginate" : false, // 翻页功能
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"bSort" : false, // 排序功能
						"bInfo" : false,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
						"sScrollX" : "100%",
						"sScrollXInner" : "110%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../../kpi/failurecount/getUserTable",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$
									.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"beginDate" : beginDate,
											"endDate" : endDate,
											"signal_process" : signal_process,
											"failureType" : failureType,
											"interfaceType" : $("#interfaceType").val()
										}, // 以json格式传递
										"success" : function(resp) {
											fnCallback(resp.allData);
										}
									});
						},
						columns : [
								{
									data : "report_date"
								},
								{
									data : "msisdn"
								},
								{
									data : "imsi"
								},
								{
									data : "city_code"
								},
								{
									data : "failurecount",
									render : function(value,type,row){
										return "<a href='#' onclick=\"failureCountUserDetail('"
											+ row.report_date + "','"
											+ row.city_code + "','"
											+ row.msisdn + "','"
											+ row.imsi 
											+ "')\"  >"+ value + "</a>";
									}
								}]
		});
}

function failureCountUserDetail(report_date,city_code,msisdn,imsi){
	var jspType = "interfaceFailStatisticsForUser";
	var signal_process = $("#signal_process").val();
	var failureType = $("#failureType").val();
	var interfaceType= $("#interfaceType").val();
	var dateType = $("#dateType").val();
	
	var url="/kpi/userFailureLink/index?beginDate="+report_date+"&endDate="+report_date
	+"&city_code="+city_code+"&msisdn="+msisdn+"&imsi="+imsi+"&jspType="+jspType
	+"&procedureType="+signal_process+"&failureType="+failureType+"&interfaceType="+interfaceType+"&dateType="+dateType;
	linkTab("失败用户",url);
}

function initAPNTable(){
	var beginDate=$("#beginDate").val();
	var endDate=$("#endDate").val();
	var signal_process=$("#signal_process").val();
	var failureType=$("#failureType").val();
	$("#apnTable tbody tr").remove();
	if (apnTable == undefined || apnTable == "undefined" || apnTable == null) {
	} else {
		apnTable.destroy();
	}
	apnTable = $('#apnTable')
			.DataTable(
					{
						"aoColumnDefs" : [ {
							sDefaultContent : '',
							aTargets : [ '_all' ]
						} ],
						"bPaginate" : false, // 翻页功能
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"bSort" : false, // 排序功能
						"bInfo" : false,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
						"sScrollX" : "100%",
						"sScrollXInner" : "110%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../../kpi/failurecount/getApnTable",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$
									.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"beginDate" : beginDate,
											"endDate" : endDate,
											"signal_process" : signal_process,
											"failureType" : failureType,
											"interfaceType" : $("#interfaceType").val()
										}, // 以json格式传递
										"success" : function(resp) {
											fnCallback(resp.allData);
										}
									});
						},
						columns : [
								{
									data : "report_date"
								},
								{
									data : "apn"
								},
								{
									data : "failurecount",
									render : function(value,type,row){
										return "<a href='#' onclick=\"failureCountApnDetail('"
											+ row.report_date + "','"
											+ row.apn
											+ "')\"  >"+ value + "</a>";
									}
								}]
		});
}

function failureCountApnDetail(report_date,apn){
	var jspType = "interfaceFailStatisticsForApn";
	var signal_process = $("#signal_process").val();
	var failureType = $("#failureType").val();
	var interfaceType= $("#interfaceType").val();
	var dateType = $("#dateType").val();
	
	var url="/kpi/userFailureLink/index?beginDate="+report_date+"&endDate="+report_date+"&apn="+apn+"&jspType="+jspType
	+"&procedureType="+signal_process+"&failureType="+failureType+"&interfaceType="+interfaceType+"&dateType="+dateType;
	linkTab("失败用户",url);
}

function forwordAPN() {
	var cityCode=$("#sgw").val();
	var beginDate=$("#beginDate").val();
	var endDate=$("#endDate").val();
	var dimType="area";
	var url = "/businessAnalysis/apnPerformance/index?dimType="+dimType+"&beginDate="+beginDate+"&endDate="+endDate+"&cityCode="+cityCode;
	linkTab("APN性能分析", url);
}